#include "Precomp.h"
#include "Tile.h"
#include "Renderer.h"
#include "Map.h"

Tile::Tile(const SQChar *path)
	:SpriteBased(Entity::TILE,path)
{
	tilerect=shape_impl.GetSubRect();
}

void Tile::setRect(int left,int top,int bottom,int right)
{
	tilerect.Left=left;
	tilerect.Top=top;
	tilerect.Bottom=bottom;
	tilerect.Right=right;
	size.x=(float)tilerect.GetWidth();
	size.y=(float)tilerect.GetHeight();
	shape_impl.SetSubRect(tilerect);
}

void Tile::serialize(SquirrelObject& out) const
{
	SpriteBased::serialize(out);
	out.SetValue(L"rectL",tilerect.Left);
	out.SetValue(L"rectT",tilerect.Top);
	out.SetValue(L"rectB",tilerect.Bottom);
	out.SetValue(L"rectR",tilerect.Right);
	if(m_obj.IsNull())//this tile is not inherited
		out.SetValue(L"type",L"Tile");
}

void Tile::deserialize(SquirrelObject& in)
{
	SpriteBased::deserialize(in);
	setRect(in.GetInt(L"rectL"),in.GetInt(L"rectT"),in.GetInt(L"rectB"),in.GetInt(L"rectR"));
}

Tile::~Tile()
{
}